home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / misc / WHDLoaddev.lha / WHDLoad / Include / whdload.i
Text File  |  1997-08-31  |  12KB  |  414 lines

  1.  
  2.  IFND WHDLOAD_I
  3. WHDLOAD=1
  4.  
  5.     IFND    EXEC_EXECBASE_I
  6.     INCLUDE    exec/execbase.i
  7.     ENDC
  8.     IFND    EXEC_TYPES_I
  9.     INCLUDE    exec/types.i
  10.     ENDC
  11.     IFND    HARDWARE_CIA_I
  12.     INCLUDE    hardware/cia.i
  13.     ENDC
  14.     IFND    HARDWARE_CUSTOM_I
  15.     INCLUDE    hardware/custom.i
  16.     ENDC
  17.     IFND    HARDWARE_INTBITS_I
  18.     INCLUDE    hardware/intbits.i
  19.     ENDC
  20.     IFND    HARDWARE_DMABITS_I
  21.     INCLUDE    hardware/dmabits.i
  22.     ENDC
  23.     IFND    UTILITY_TAGITEM_I
  24.     INCLUDE    utility/tagitem.i
  25.     ENDC
  26.  
  27. ;some custom stuff
  28.  
  29.  BITDEF POTGO,OUTRY,15
  30.  BITDEF POTGO,DATRY,14
  31.  BITDEF POTGO,OUTRX,13
  32.  BITDEF POTGO,DATRX,12
  33.  BITDEF POTGO,OUTLY,11
  34.  BITDEF POTGO,DATLY,10
  35.  BITDEF POTGO,OUTLX,9
  36.  BITDEF POTGO,DATLX,8
  37.  BITDEF POTGO,START,0
  38.  
  39. _ciaa        = $bfe001
  40. _ciab        = $bfd000
  41. _custom        = $dff000
  42.  
  43. ;=============================================================================
  44. ;    misc
  45. ;=============================================================================
  46.  
  47. SLAVE_DEFNAME    MACRO
  48.         dc.b    "WHDLoad.Slave",0
  49.         ENDM
  50.  
  51. SLAVE_SECURITY    MACRO
  52.         moveq    #-1,d0
  53.         rts
  54.         ENDM
  55.  
  56. SLAVE_ID    MACRO
  57.         dc.b    "WHDLOADS"
  58.         ENDM
  59.  
  60. SLAVE_HEADER    MACRO
  61.         SLAVE_SECURITY
  62.         SLAVE_ID
  63.         ENDM
  64.  
  65. ;=============================================================================
  66. ;    some useful macros
  67. ;=============================================================================
  68.  
  69. ****************************************************************
  70. ***** write opcode ILLEGAL to specified address
  71. ill    MACRO
  72.     IFNE    NARG-1
  73.         FAIL    arguments "ill"
  74.     ENDC
  75.         move.w    #$4afc,\1
  76.     ENDM
  77.  
  78. ****************************************************************
  79. ***** write opcode RTS to specified address
  80. ret    MACRO
  81.     IFNE    NARG-1
  82.         FAIL    arguments "ret"
  83.     ENDC
  84.         move.w    #$4e75,\1
  85.     ENDM
  86.  
  87. ****************************************************************
  88. ***** write \1 times opcode NOP starting at address \2
  89. nops    MACRO
  90.     IFNE    NARG-2
  91.         FAIL    arguments "nops"
  92.     ENDC
  93.         movem.l    d0/a0,-(a7)
  94.         IFGT \1-128
  95.             move.w    #\1-1,d0
  96.         ELSE
  97.             moveq    #\1-1,d0
  98.         ENDC
  99.         lea    \2,a0
  100. .lp\@        move.w    #$4e71,(a0)+
  101.         dbf    d0,.lp\@
  102.         movem.l    (a7)+,d0/a0
  103.     ENDM
  104.  
  105. ****************************************************************
  106. ***** write opcode JMP \2 to address \1
  107. patch    MACRO
  108.     IFNE    NARG-2
  109.         FAIL    arguments "patch"
  110.     ENDC
  111.         move.w    #$4ef9,\1
  112.         pea    \2
  113.         move.l    (a7)+,2+\1
  114.     ENDM
  115.  
  116. ****************************************************************
  117. ***** write opcode JSR \2 to address \1
  118. patchs    MACRO
  119.     IFNE    NARG-2
  120.         FAIL    arguments "patchs"
  121.     ENDC
  122.         move.w    #$4eb9,\1
  123.         pea    \2
  124.         move.l    (a7)+,2+\1
  125.     ENDM
  126.  
  127. ****************************************************************
  128. ***** wait that blitter has finished his job
  129. ***** (this is adapted from graphics.WaitBlit, see autodocs for
  130. *****  hardware bugs and possible problems ...)
  131. ***** if \1 is given it must be an address register containing _custom
  132. BLITWAIT MACRO
  133.     IFEQ    NARG-1
  134.         tst.b    (dmaconr,\1)
  135. .waitb\@    tst.b    (_ciaa)        ;this avoids blitter slow down
  136.         tst.b    (_ciaa)
  137.         btst    #DMAB_BLTDONE-8,(dmaconr,\1)
  138.         bne.b    .waitb\@
  139.         tst.b    (dmaconr,\1)
  140.     ELSE
  141.         tst.b    (_custom+dmaconr)
  142. .waitb\@    tst.b    (_ciaa)        ;this avoids blitter slow down
  143.         tst.b    (_ciaa)
  144.         btst    #DMAB_BLTDONE-8,(_custom+dmaconr)
  145.         bne.b    .waitb\@
  146.         tst.b    (_custom+dmaconr)
  147.     ENDC
  148.     ENDM
  149.  
  150. ****************************************************************
  151. ***** wait of vertical blank
  152. ***** if \1 is given it must be an address register containing _custom
  153. waitvb    MACRO
  154.     IFEQ    NARG-1
  155. .loop1\@    btst    #0,(vposr+1,\1)
  156.         beq    .loop1\@
  157. .loop2\@    btst    #0,(vposr+1,\1)
  158.         bne    .loop2\@
  159.     ELSE
  160. .loop1\@    btst    #0,(_custom+vposr+1)
  161.         beq    .loop1\@
  162. .loop2\@    btst    #0,(_custom+vposr+1)
  163.         bne    .loop2\@
  164.     ENDC
  165.     ENDM
  166.  
  167. ****************************************************************
  168. ***** wait for pressing any button
  169. waitbutton    MACRO
  170.     IFNE    NARG
  171.         FAIL    arguments "waitbutton"
  172.     ENDC
  173.         move.l    a0,-(a7)
  174.         lea    (_custom),a0
  175. .down\@        bsr    .wait\@
  176.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  177.         beq    .up\@
  178.         btst    #POTGOB_DATLY-8,(potinp,a0)        ;RMB
  179.         beq    .up\@
  180.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  181.         bne    .down\@
  182. .up\@        bsr    .wait\@                    ;entprellen
  183.         btst    #CIAB_GAMEPORT0,(ciapra+_ciaa)        ;LMB
  184.         beq    .up\@
  185.         btst    #POTGOB_DATLY-8,(potinp,a0)        ;RMB
  186.         beq    .up\@
  187.         btst    #CIAB_GAMEPORT1,(ciapra+_ciaa)        ;FIRE
  188.         beq    .up\@
  189.         bsr    .wait\@                    ;entprellen
  190.         bra    .done\@
  191. .wait\@        waitvb    a0
  192.         rts
  193. .done\@        move.l    (a7)+,a0
  194.     ENDM
  195.  
  196. ****************************************************************
  197. ***** flash the screen and wait for LMB
  198. blitz        MACRO
  199.         move    #$4200,bplcon0+_custom
  200.         move.l    d0,-(a7)
  201. .lpbl\@        move.w    d0,$dff180
  202.         subq.w    #1,d0
  203.         btst    #6,$bfe001
  204.         bne    .lpbl\@
  205.         waitvb            ;entprellen
  206. .lp2bl\@    move.w    d0,$dff180
  207.         subq.w    #1,d0
  208.         btst    #6,$bfe001
  209.         beq    .lp2bl\@
  210.         move.l    (a7)+,d0
  211.         ENDM
  212.  
  213. ****************************************************************
  214. ***** install Vertical-Blank-Interrupt which quits on LMB pressed
  215. QUITVBI        MACRO
  216.         move.l    a0,-(a7)
  217.         lea    .vbi,a0
  218.         move.l    a0,$6c
  219.         bra    .g
  220. .vbi        btst    #6,$bfe001
  221.         beq    .vbi+1        ;create "address error"
  222.         move.w    #INTF_VERTB,_custom+intreq
  223.         rte
  224. .g        move.w    #INTF_SETCLR|INTF_INTEN|INTF_VERTB,_custom+intena
  225.         move.w    #INTF_VERTB,_custom+intreq
  226.         move.l    (a7)+,a0
  227.     ENDM
  228.  
  229. ;=============================================================================
  230. ;    return-values for termination (resload_Abort)
  231. ;=============================================================================
  232.  
  233. TDREASON_OK        = -1    ;normal termination
  234. TDREASON_DOSREAD    = 1    ;error with resload_ReadFile
  235. TDREASON_DOSWRITE    = 2    ;error with resload_SaveFile/resload_SaveFileOffset
  236. TDREASON_EXCEPTION    = 3    ;(private)
  237. TDREASON_RESET        = 4    ;(private)
  238. TDREASON_DEBUG        = 5    ;make coredump and quit
  239. TDREASON_DOSLIST    = 6    ;error with resload_ListFiles
  240. TDREASON_DISKLOAD    = 7    ;error with resload_DiskLoad
  241. TDREASON_DISKLOADDEV    = 8    ;error with resload_DiskLoadDev
  242. TDREASON_WRONGVER    = 9    ;an version check (e.g. crc16) has detected an
  243.                 ;unsupported version of data files
  244. TDREASON_MMUTABLE    = 9995    ;(private) incomplete mmu translation tree
  245. TDREASON_BADSP        = 9996    ;(private) illegal sp on entering whdload
  246. TDREASON_ILLEGALARGS    = 9997    ;(private) illegal parameters to a resload_#? function
  247. TDREASON_BADVERSION    = 9998    ;(private) resload_#? function call and bad ws_Version
  248. TDREASON_FALSEMODE    = 9999    ;(private) internal mode check
  249.  
  250. ;=============================================================================
  251. ; tagitems for various resload functions
  252. ;=============================================================================
  253.  
  254.  ENUM    TAG_USER+$8000000
  255.  EITEM    WHDLTAG_ATTNFLAGS_GET    ;get the AttnFlags
  256.  EITEM    WHDLTAG_ECLOCKFREQ_GET    ;get the EClockFrequency
  257.  
  258. ;=============================================================================
  259. ; Slave        Version 1..3
  260. ;=============================================================================
  261.  
  262.     STRUCTURE    WhdloadSlave,0
  263.     STRUCT    ws_Security,4    ;moveq #-1,d0 + rts
  264.     STRUCT    ws_ID,8        ;"WHDLOADS"
  265.     UWORD    ws_Version    ;version of Whdload that is required
  266.     UWORD    ws_Flags    ;see below
  267.     ULONG    ws_BaseMemSize    ;size of mem required by game
  268.                 ;(must be multiple of $1000, max=$200000)
  269.     ULONG    ws_ExecInstall    ;address in BaseMem where is space for a fake
  270.                 ;ExecLibrary installed by the WHDLoad to
  271.                 ;survive a RESET
  272.                 ;for example $400
  273.                 ;required are at least 84 Bytes
  274.                 ;=0 means unsupported
  275.     RPTR    ws_GameLoader    ;start of slave-code
  276.                 ;will called from WHDLoad after init in
  277.                 ;SuperVisor
  278.                 ;slave must be 100.00% PC-RELATIVE !
  279.     RPTR    ws_CurrentDir    ;subdirectory in which WHDLoad should search
  280.                 ;for files
  281.     RPTR    ws_DontCache    ;pattern string for files which must not cached
  282.                 ;starting WHDLoad 0.107 this is obsolete
  283.  
  284. ;=============================================================================
  285. ; additional    Version 4..5
  286. ;=============================================================================
  287.  
  288.     UBYTE    ws_keydebug    ;raw key code to quit with debug
  289.                 ;works only if vbr is moved !
  290.                 ;=0 means no key
  291.     UBYTE    ws_keyexit    ;raw key code to exit
  292.                 ;works only if vbr is moved !
  293.                 ;=0 means no key
  294.     LABEL    ws_SIZEOF
  295.  
  296. ;=============================================================================
  297. ; Flags for ws_Flags
  298.  
  299.     BITDEF WHDL,Disk,0    ;means diskimages are used by the slave
  300.                 ;result is a different PRELOAD
  301.                 ;starting WHDLoad 0.107 this is obsolete
  302.     BITDEF WHDL,NoError,1    ;if enabled every error occuring in a 
  303.                 ;resload_#? function will immedately quit the
  304.                 ;slave, and whdload will prompt an error
  305.                 ;requester
  306.     BITDEF WHDL,EmulTrap,2    ;if set and the vbr is moved TRAP #0-15 are
  307.                 ;emulated like the the autovectors
  308.  
  309. ;=============================================================================
  310. ; resload_#? functions
  311. ; a JMP-tower in WHDLoad (similar to a library)
  312. ; base is given on startup via A0
  313. ;=============================================================================
  314.  
  315.     STRUCTURE    ResidentLoader,0
  316.     ULONG    resload_Install        ;(private)
  317.     ULONG    resload_Abort
  318.         ; return to operating system
  319.         ; IN: (a7) = ULONG success (one of TDREASON_xxx)
  320.         ;   (4,a7) = ULONG primary error code
  321.         ;   (8,a7) = ULONG secondary error code
  322.         ; OUT :    -
  323.         ; DANGER this routine must called via JMP ! (not JSR)
  324.     ULONG    resload_LoadFile
  325.         ; load to BaseMem
  326.         ; IN :    a0 = CPTR  name of file
  327.         ;    a1 = APTR  address
  328.         ; OUT :    d0 = BOOL  success (size of file)
  329.         ;    d1 = ULONG dos errcode (0 if all went ok)
  330.     ULONG    resload_SaveFile
  331.         ; save from BaseMem
  332.         ; IN :    d0 = LONG  length to save
  333.         ;    a0 = CPTR  name of file
  334.         ;    a1 = APTR  address
  335.         ; OUT :    d0 = BOOL  success
  336.         ;    d1 = ULONG dos errcode (0 if all went ok)
  337.     ULONG    resload_SetCACR
  338.         ; sets the CACR (also ok with 68000's and from user-state)
  339.         ; IN :    d0 = ULONG new cacr
  340.         ;    d1 = ULONG mask (bits to change)
  341.         ; OUT :    d0 = ULONG old cacr
  342.     ULONG    resload_ListFiles
  343.         ; list files in dir to buffer
  344.         ; IN :    d0 = ULONG buffer size (a1)
  345.         ;    a0 = CPTR  name of directory to scan (relative)
  346.         ;    a1 = APTR  buffer (MUST reside in Slave !!!)
  347.         ; OUT :    d0 = ULONG amount of listed names
  348.         ;    d1 = ULONG dos errcode (0 if all went ok)
  349.     ULONG    resload_Decrunch
  350.         ; decrunch memory
  351.         ; IN :    a0 = APTR  source
  352.         ;    a1 = APTR  destination (can be equal to source)
  353.         ; OUT :    d0 = BOOL  success (size of file unpacked)
  354.     ULONG    resload_LoadFileDecrunch
  355.         ; IN :    a0 = CPTR  name of file (anywhere)
  356.         ;    a1 = APTR  address (MUST inside BaseMem !!!)
  357.         ; OUT :    d0 = BOOL  success (size of file)
  358.         ;    d1 = ULONG dos errcode (0 if all went ok)
  359.     ULONG    resload_FlushCache
  360.         ; flush all caches
  361.         ; IN :    -
  362.         ; OUT :    -
  363.     ULONG    resload_GetFileSize
  364.         ; IN :    a0 = CPTR  name of file
  365.         ; OUT :    d0 = LONG  size of file or 0 if does'nt exist
  366.     ULONG    resload_DiskLoad
  367.         ; IN :    d0 = ULONG offset
  368.         ;    d1 = ULONG size
  369.         ;    d2 = ULONG disk number
  370.         ;    a0 = APTR  destination
  371.         ; OUT :    d0 = BOOL  success
  372.         ;    d1 = ULONG dos errorcode (if failed)
  373.         
  374. ******* the following functions require ws_Version >= 2
  375.  
  376.     ULONG    resload_DiskLoadDev
  377.         ; IN :    d0 = ULONG offset
  378.         ;    d1 = ULONG size
  379.         ;    a0 = APTR  destination
  380.         ;    a1 = APTR  taglist
  381.         ; OUT :    d0 = BOOL  success
  382.         ;    d1 = ULONG trackdisk errorcode (if failed)
  383.         
  384. ******* the following functions require ws_Version >= 3
  385.  
  386.     ULONG    resload_CRC16
  387.         ; IN :    d0 = ULONG length
  388.         ;    a0 = APTR  address
  389.         ; OUT :    d0 = UWORD crc checksum
  390.  
  391. ******* the following functions require ws_Version >= 5
  392.  
  393.     ULONG    resload_Control
  394.         ; IN :    a0 = APTR  taglist
  395.         ; OUT :    d0 = BOOL  success
  396.     ULONG    resload_SaveFileOffset
  397.         ; save from BaseMem
  398.         ; IN :    d0 = ULONG length to save
  399.         ;    d1 = ULONG offset
  400.         ;    a0 = CPTR  name of file
  401.         ;    a1 = APTR  address
  402.         ; OUT :    d0 = BOOL  success
  403.         ;    d1 = ULONG dos errcode (0 if all went ok)
  404.     LABEL    resload_SIZEOF
  405.  
  406. ******* compatibility to older whdload versions :
  407.  
  408. resload_CheckFileExist = resload_GetFileSize
  409.  
  410. ;=============================================================================
  411.  
  412.  ENDC
  413.  
  414.